//
//  FunctionIntroduceViewController.m
//  MIS Cloud
//
//  Created by goldeney on 13-12-30.
//  Copyright (c) 2013年 goldeneye. All rights reserved.
//

#import "FunctionIntroduceViewController.h"
#import "GEIntroductionPanel.h"
#import "Reachability.h"
#import "UserLoginNSCoding.h"
#import "UserLoginViewController.h"

#import "ExitLoginService.h"
#import "NSKeyedArchiverUserLogin.h"

@interface FunctionIntroduceViewController ()

@end

@implementation FunctionIntroduceViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self buildIntro];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
    
    MainAppDelegate *application = (MainAppDelegate*)[[UIApplication sharedApplication] delegate];
    [application.navigationController setNavigationBarHidden:YES animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    MainAppDelegate *application = (MainAppDelegate*)[[UIApplication sharedApplication] delegate];
    [application.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Build UIButton

- (void)buildButtonAddView:(UIView*)view
{
    CGRect frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(60, frame.size.height - 70, frame.size.width - 120, 60);
    [button addTarget:self action:@selector(closeFunctionIntroduce) forControlEvents:UIControlEventTouchUpInside];
    //button.backgroundColor = ThemeColorBlue;
    [view addSubview:button];
}

#pragma mark - Build MYBlurIntroductionView

-(void)buildIntro
{
    //Create Stock Panel with header
    CGRect frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    GEIntroductionPanel *panel1 = [[GEIntroductionPanel alloc] initWithFrame:frame imageNamed:@"guidance_01"];
    GEIntroductionPanel *panel2 = [[GEIntroductionPanel alloc] initWithFrame:frame imageNamed:@"guidance_02"];
    GEIntroductionPanel *panel3 = [[GEIntroductionPanel alloc] initWithFrame:frame imageNamed:@"guidance_03"];
    
    //Add panels to an button
    [self buildButtonAddView:panel3];
    
    //Add panels to an array
    NSArray *panels = @[panel1, panel2, panel3];
    
    //Create the introduction view and set its delegate
    GEBlurIntroductionView *introductionView = [[GEBlurIntroductionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    introductionView.delegate = self;
    [introductionView.RightSkipButton setTitleColor:ThemeColorBlue forState:UIControlStateNormal];
    introductionView.RightSkipButton.hidden = YES;
    
    //Build the introduction with desired panels
    [introductionView buildIntroductionWithPanels:panels];
    
    //Add the introduction to your view
    [self.view addSubview:introductionView];
}

#pragma mark - MYIntroduction Delegate

-(void)introduction:(GEBlurIntroductionView *)introductionView didChangeToPanel:(GEIntroductionPanel *)panel withIndex:(NSInteger)panelIndex
{
    NSLog(@"Introduction did change to panel %ld", (long)panelIndex);
    //You can edit introduction view properties right from the delegate method!
    //If it is the first panel, change the color to green!
}

-(void)introduction:(GEBlurIntroductionView *)introductionView didFinishWithType:(GEFinishType)finishType
{
    NSLog(@"Introduction did finish");
    if (finishType == GEFinishTypeSkipButton)
    [self closeFunctionIntroduce];
    
}

#pragma mark -关闭页面

- (void)closeFunctionIntroduce
{
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:FirstInstallLaunched];//判断是否第一次安装
    
    UserLoginNSCoding *userInfo = [NSKeyedArchiverUserLogin getUserLoginData];
    if (userInfo) {
        //功能介绍
        [self.navigationController popViewControllerAnimated:YES];
    } else {
        //清理缓存数据,并跳转到指定页面
        [ExitLoginService clearUserLoginData];
    }
}

@end
